
<div id="append_parent"></div>
<div class="container" id="cpcontainer">
	<div class="itemtitle"><h3>{{if empty($goodsInfo)}}新增{{else}}编辑{{/if}}商品</h3></div>
	<table class="tb tb2 ">
	<tbody>
		<tr>
			<td colspan="2" class="td27">商品名称:</td>
		</tr>
		<tr class="noborder">
			<td class="vtop rowform"><input name="name" value="{{$goodsInfo.name}}" type="text" class="txt"></td>
			<td class="vtop tips2"></td>
		</tr>

		<tr>
			<td colspan="2" class="td27">分类id:</td>
		</tr>
		<tr class="noborder">
			<td class="vtop rowform"><input name="cid" value="{{$goodsInfo.cid}}" type="text" class="txt"></td>
			<td class="vtop tips2"></td>
		</tr>

		<tr>
			<td colspan="2" class="td27">商品描述:</td>
		</tr>
		<tr class="noborder">
			<td class="vtop rowform"><textarea class="tarea" style="width:500px;height:200px;" name="description">{{$goodsInfo.description}}</textarea></td>
			<td class="vtop tips2"></td>
		</tr>

		<tr>
			<td colspan="2">
				<input name="gid" value="{{$goodsInfo.gid}}" type="hidden" class="txt">
				<input type="button" class="btn" value="提交" id="_j_goods_edit_submit">
			</td>
		</tr>
	</tbody>
	</table>
</div>


<script>
K.App('apps/admin/AGoods.js', ['jQuery']).define(function() {

    var $ = this.require('jQuery');

    return {

		'container' : '#cpcontainer',

        'events' : {
            'click #_j_goods_edit_submit' : 'onGoodsEditSubmit'
        },

        'main' : function() {
        },

        'onGoodsEditSubmit' : function(evt) {
        	var ctx = this.getContainer(),
        		name = ctx.find(':text[name=name]').val(),
        		cid = ctx.find(':text[name=cid]').val(),
        		gid = ctx.find(':hidden[name=gid]').val(),
        		desc = ctx.find('textarea[name=description]').val();
        	
			// 确认
			if (!confirm('您确定提交么？')) {
				return;
			}

           	// 提交结果
           	$.ajax({
           		'url' : '/admin/ajax/goods_edit.php',
           		'data' : {'gid':gid, 'name':name, 'cid':cid, 'description':desc},
           		'type' : 'POST',
           		'success' : function(data){
                    	data = $.parseJSON(data);
                    	if (data.error) {
                    		alert(data.error.errmsg);
                    	} else {
                    		ctx.find(':hidden[name=gid]').val( data.payload.gid );
                    		alert('提交成功');
                    	}
           		}
           	});
        }
    }
});
</script>